package no.doomsday.scripting.simplescriptengine.scriptevents 
{
	import com.adobe.utils.StringUtil;
	import no.doomsday.scripting.simplescriptengine.ScriptCore;
	/**
	 * ...
	 * @author Andreas Rønning (andreas@doomsday.no)
	 */
	public class ScriptBranchFactory
	{
		public static function getBranches(scr:String,core:ScriptCore):Vector.<IScriptBranch> {
			var v:Vector.<IScriptBranch> = new Vector.<IScriptBranch>();
			var branchSplit:Array = scr.split("branch ");
			for (var i:int = 0; i < branchSplit.length; i++) 
			{
				if (branchSplit[i].length == 0) continue;
				var str:String = branchSplit[i];
				var braceIndex:int = str.indexOf("{");
				var idSlice:String = str.slice(0, braceIndex);
				var scriptBlock:String = str.split("{")[1].split("}")[0];
				scriptBlock = StringUtil.trim(scriptBlock);
				core.print("Script block '" + scriptBlock + "'");
				var branch:ScriptEventBranch = new ScriptEventBranch(idSlice, scriptBlock, core);
				v.push(branch);
			}
			return v;
		}
		
	}

}